<script>

export default {
  name: "qrcode-poster",
  data() {
    return {
      imageList: [],
      bigImageSrc: "",
      qrcode: ""
    };
  },
  methods: {
    selectPicture() {
      this.$refs.pictureInputRef.click();
    },
    getPicture() {
      const src = URL.createObjectURL(this.$refs.pictureInputRef.files[0]);
      const image = {
        src,
        select: true
      };
      this.imageList.push(image);
      this.selectOne(image);
    },
    selectOne(image) {
      this.bigImageSrc = image.src;
      this.imageList.map(m => {
        m.select = false;
        return m;
      });
      image.select = true;
    },
    selectQrcode() {
      this.$refs.qrcodeInputRef.click();
    },
    getQrcode() {
      this.qrcode = URL.createObjectURL(this.$refs.qrcodeInputRef.files[0]);
    }
  }
};
</script>

<template>
  <div>
    <el-row>
      <el-col :span="16" :offset="1">
        <div class="big-image-box">
          <el-image v-if="bigImageSrc" :src="bigImageSrc"></el-image>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="right-side">
          <div>
            <div class="box-title">添加背景图</div>
            <div class="small-image-box">
              <div v-for="(image, index) in imageList" :key="index">
                <div class="my-img" :class="image.select ? 'active' : ''" @click="selectOne(image)">
                  <img v-if="image.src" :src="image.src" alt="" class="avatar" >
                </div>
              </div>
              <div>
                <div class="my-img" @click="selectPicture">
                  <el-icon class="avatar-uploader-icon">
                    <Plus />
                  </el-icon>
                  <input ref="pictureInputRef" type="file" accept=".png,.jpg,jpeg" style="display: none"
                         @change="getPicture">
                </div>
              </div>
            </div>
          </div>
          <div>
            <div class="box-title">添加二维码</div>
            <div class="small-image-box">
              <div>
                <div class="my-img" @click="selectQrcode">
                  <img v-if="qrcode" :src="qrcode" alt="" class="avatar" >
                  <el-icon v-else class="avatar-uploader-icon">
                    <Plus />
                  </el-icon>
                  <input ref="qrcodeInputRef" type="file" accept=".png,.jpg,jpeg" style="display: none"
                         @change="getQrcode">
                </div>
              </div>
            </div>
          </div>
          <div>
            <div class="box-title">添加主题</div>
            <div class="text-input">
              <el-input type="textarea"></el-input>
            </div>
          </div>
          <div>
            <el-button type="primary" style="width: 200px;margin-top: 10px;">提交</el-button>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>

.my-img {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 100px;
  height: 100px;
  padding: 2px;
  margin: 5px;
}

.my-img:hover {
  border-color: #409EFF;
}

.active {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}

.avatar {
  width: 100px;
  height: 100px;
  display: block;
}

.big-image-box {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  width: 375px;
  height: 667px;
  margin: auto;
}

.small-image-box {
  display: flex;
  justify-content: left;
  flex-flow: wrap;
}

.box-title {
  text-align: left;
  font-size: 18px;
  font-weight: 600;
  background-color: lightgray;
  padding: 5px;
  border-radius: 5px;
}

.right-side {
  border-left: 1px dashed #d9d9d9;
  padding: 0 5px;
  height: 100%;
}

.text-input {
  margin-top: 5px;
}
</style>
